package cn.edu.lingnan.translation.controller;

import cn.edu.lingnan.translation.entity.UserVideoManage;
import cn.edu.lingnan.translation.entity.vo.UserVideoManageQueryVo;
import cn.edu.lingnan.translation.service.UserVideoManageService;
import cn.edu.lingnan.translation.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userVideoManager")
public class UserVideoManageController {
    @Autowired
    private UserVideoManageService userVideoManageService;

    @ApiOperation(value = "获取用户音频管理分页列表")
    @PostMapping("/{page}/{limit}")
    public R getUserVideoManage(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit,
            @ApiParam(name = "UserVideoManageQueryVo", value = "查询对象", required = false)
            @RequestBody UserVideoManageQueryVo userVideoManageQueryVo){
        Page<UserVideoManage> userVideoManagePage = new Page<>(page,limit);

        //查询条件
        QueryWrapper<UserVideoManage> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(userVideoManageQueryVo.getTheme())){
            wrapper.like("theme", userVideoManageQueryVo.getTheme());
        }
        if (!StringUtils.isEmpty(userVideoManageQueryVo.getTitle())){
            wrapper.like("title", userVideoManageQueryVo.getTitle());
        }
        if (!StringUtils.isEmpty(userVideoManageQueryVo.getType())){
            wrapper.like("type", userVideoManageQueryVo.getType());
        }
        if (!StringUtils.isEmpty(userVideoManageQueryVo.getUserName())){
            wrapper.like("userName", userVideoManageQueryVo.getUserName());
        }
        if (!StringUtils.isEmpty(userVideoManageQueryVo.getUserSex())){
            wrapper.like("userSex", userVideoManageQueryVo.getUserSex());
        }
        IPage<UserVideoManage> iPage = userVideoManageService.getUserVideoManage(userVideoManagePage,wrapper);
        return R.ok().data("userVideoManage", iPage.getRecords()).data("total", iPage.getTotal());
    }

    @ApiOperation(value = "题库更新")
    @PostMapping("/save")
    public R updateUserVideoManager(@RequestBody UserVideoManage userVideoManage){
        userVideoManageService.updateUserVideoManage(userVideoManage);
        return R.ok();
    }
}
